package com.hujh.android.ui;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;

import com.hujh.android.R;
import com.hujh.android.adapter.ImageViewAdapter;

public class GridViewActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gridview);

		//取得GridView对象
		GridView gridview = (GridView) findViewById(R.id.gridview);
		//添加元素给gridview
		gridview.setAdapter(new ImageViewAdapter(this));

		// 设置Gallery的背景
		//gridview.setBackgroundResource(Color.BLUE);

		//事件监听
		gridview.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View v, int position, long id)
			{
				Toast.makeText(GridViewActivity.this, "你选择了" + (position + 1) + " 号图片", Toast.LENGTH_SHORT).show();
			}
		});
	}
	
	
}
